package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.Member;
import com.fantastic.model.pojo.zjs.MemberCoupons;
import com.fantastic.service.zjs.MemberCouponsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/6/4 20:15
 * @description:    会员卡优惠券关联信息请求控制器
 */
@RestController
@RequestMapping("/memberCoupons")
public class MemberCouponsControllerAdmin {
    @Resource
    private MemberCouponsService memberCouponsService;

    /**
     * 查询会员卡优惠券关联信息
     *
     * @param memberCoupons
     * @param pageSize
     * @param pageNum
     * @return
     */
    @PostMapping("/listMembersCoupons")
    public ResultData listMembersCoupons(MemberCoupons memberCoupons,
                                         @RequestParam(name="page",
                                                 defaultValue = "1") int pageNum,
                                         @RequestParam(name="limit",defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<MemberCoupons> list = memberCouponsService.listMembersCoupons(memberCoupons);
        PageInfo<MemberCoupons> pageInfo = new PageInfo<>(list);
        return new ResultData(RespStatusInfo.OK, pageInfo);
    }

    /**
     * 查询单个会员卡优惠券关联信息
     *
     * @param couponsId
     * @param memberId
     * @return
     */
    @PostMapping("/getMemberCoupons")
    public ResultData getMemberCoupons(Integer memberId, Integer couponsId) {
        return new ResultData(RespStatusInfo.OK, memberCouponsService.getMemberCoupons(memberId, couponsId));
    }

    /**
     * 添加会员卡优惠券关联信息
     *
     * @param memberCoupons
     * @return
     */
    @PostMapping("/insertMemberCoupons")
    public ResultData insertMemberCoupons(MemberCoupons memberCoupons) {
        return new ResultData(RespStatusInfo.OK, memberCouponsService.insertMemberCoupons(memberCoupons));
    }


    /**
     * 删除会员卡优惠券关联信息
     *
     * @param couponsId
     * @param memberId
     * @return
     */
    @DeleteMapping("/deleteMemberCoupons")
    public ResultData deleteMemberCoupons(Integer memberId, Integer couponsId) {
        return new ResultData(RespStatusInfo.OK, memberCouponsService.deleteMemberCoupons(memberId, couponsId));
    }


}
